﻿import QtQuick 2.0
import QtQuick.Controls 2.0
import QtGraphicalEffects 1.12

Rectangle{
    id: closeRect
    color: "#20212C"

    signal shotDownApp()

    Image{
        anchors.fill: parent
        source:  "qrc:/imgs/bg_img.png"
        fillMode: Image.PreserveAspectCrop
        opacity: 0.1
        asynchronous: true
    }

    Rectangle{
        id: dragRect
        x: 330
        y: 310
        width: 647
        height: 145
        radius: 200
        gradient: Gradient {
            GradientStop {position: 0.0; color: "#B1D7DF"}
            GradientStop {position: 0.9; color: "#87E9FF"}
        }

        Text {
            id: closeText
            text: "   滑动来关机"
            anchors.centerIn: parent
            font{
                family: "Microsoft YaHei"
                pixelSize: 40
            }
            Image {
                anchors.verticalCenter: parent.verticalCenter
                source: "qrc:/imgs/jiandou.png"
            }
        }

        Rectangle{
            id: closeBar
            x: 9
            width: 126
            height: 126
            radius: width/2
            anchors.verticalCenter: parent.verticalCenter
            color: "white"
            Image {
                anchors.centerIn: parent
                source: "qrc:/imgs/close_1.png"
            }

            MouseArea{
                id: mouseDrag
                anchors.fill: parent
                drag.target: closeBar
                drag.axis: Drag.XAxis
                drag.minimumX: 9
                drag.maximumX: dragRect.width - closeBar.width - 9

                onReleased: {
//                    closeText.opacity = 1
                    if(closeBar.x < drag.maximumX){
                        closeBar.x = drag.minimumX
                    }
                    else{
                        // console.log("shot down")
                        shotDownApp()
                    }
                }
            }

            onXChanged: {
                 closeText.opacity = 1- closeBar.x / (mouseDrag.drag.maximumX - mouseDrag.drag.minimumX)
            }
        }
    }

//    Image {
//        x: 596
//        y: 604
//        source: "qrc:/imgs/close_2.png"
//        MouseArea{
//            anchors.fill: parent
//            onClicked: {
//                closeRect.visible = false
//                root.header.visible = true
//            }
//        }
//    }

//    Text {
//        color: "white"
//        text: "取消"
//        anchors.horizontalCenter: parent.horizontalCenter
//        anchors.bottom: parent.bottom
//        anchors.bottomMargin: 68
//        font{
//            family: "Microsoft YaHei"
//            pixelSize: 32
//        }
//    }
}
